//
//  UIImage+QRCode.m
//  01-二维码生成
//
//  Created by Zed on 24/1/2016.
//  Copyright © 2016 itcast. All rights reserved.
//

#import "UIImage+QRCode.h"

@implementation UIImage (QRCode)

- (UIImage *)imageWithIcon:(UIImage *)icon
{
    // 0. 开启图片的图形上下文
    UIGraphicsBeginImageContext(self.size);
    
    // 1. 先画自己
    [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
    
    // 2. 在中间画头像, 宽高都是原图的25%
    CGFloat wh = self.size.width * 0.2;
    [icon drawInRect:CGRectMake((self.size.width - wh) * 0.5, (self.size.height - wh) * 0.5, wh, wh)];
    
    // 3. 导出图像
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // 关闭上下文
    UIGraphicsEndImageContext();
    
    return newImage;
}

@end
